home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Combine
- Caption = "Combining Images"
- ClientHeight = 4200
- ClientLeft = 1095
- ClientTop = 1485
- ClientWidth = 5790
- Height = 4605
- Left = 1035
- LinkTopic = "Form3"
- ScaleHeight = 4200
- ScaleWidth = 5790
- Top = 1140
- Width = 5910
- Begin PictureBox picSaved
- Height = 510
- Left = 420
- ScaleHeight = 480
- ScaleWidth = 480
- TabIndex = 14
- Top = 2760
- Width = 510
- End
- Begin PictureBox picWork3
- Height = 510
- Left = 3600
- ScaleHeight = 480
- ScaleWidth = 480
- TabIndex = 12
- Top = 3420
- Width = 510
- End
- Begin PictureBox picWork2
- Height = 510
- Left = 3600
- ScaleHeight = 480
- ScaleWidth = 480
- TabIndex = 10
- Top = 2820
- Width = 510
- End
- Begin PictureBox picWork
- Height = 510
- Left = 3600
- ScaleHeight = 480
- ScaleWidth = 480
- TabIndex = 9
- Top = 2220
- Width = 510
- End
- Begin CommandButton cmdClose
- Caption = "Close"
- Height = 435
- Left = 2220
- TabIndex = 4
- Top = 3600
- Width = 1095
- End
- Begin PictureBox picCarMaskI
- AutoRedraw = -1 'True
- Height = 510
- Left = 3600
- ScaleHeight = 480
- ScaleWidth = 480
- TabIndex = 3
- Top = 1560
- Width = 510
- End
- Begin PictureBox picCarMask
- AutoRedraw = -1 'True
- AutoSize = -1 'True
- Height = 510
- Left = 3600
- Picture = COMBINE.FRX:0000
- ScaleHeight = 480
- ScaleWidth = 480
- TabIndex = 2
- Top = 960
- Width = 510
- End
- Begin PictureBox picCar
- AutoSize = -1 'True
- Height = 510
- Left = 3600
- Picture = COMBINE.FRX:027A
- ScaleHeight = 480
- ScaleWidth = 480
- TabIndex = 1
- Top = 360
- Width = 510
- End
- Begin PictureBox picLeafs
- AutoSize = -1 'True
- Height = 2280
- Left = 420
- MousePointer = 2 'Cross
- Picture = COMBINE.FRX:04F4
- ScaleHeight = 150
- ScaleMode = 3 'Pixel
- ScaleWidth = 200
- TabIndex = 0
- Top = 360
- Width = 3030
- End
- Begin Label Label7
- Caption = "Hold the original image segment to restore later."
- Height = 675
- Left = 1080
- TabIndex = 15
- Top = 2760
- Width = 1935
- End
- Begin Label Label6
- Caption = "Work area - step 3"
- Height = 435
- Left = 4200
- TabIndex = 13
- Top = 3420
- Width = 1275
- End
- Begin Label Label5
- Caption = "Work area - step 2"
- Height = 435
- Left = 4200
- TabIndex = 11
- Top = 2820
- Width = 1275
- End
- Begin Label Label4
- Caption = "Work area - step 1"
- Height = 375
- Left = 4200
- TabIndex = 8
- Top = 2280
- Width = 1395
- End
- Begin Label Label3
- Caption = "Inverted mask - created at runtime."
- Height = 615
- Left = 4200
- TabIndex = 7
- Top = 1560
- Width = 1395
- End
- Begin Label Label2
- Caption = "Mask to use."
- Height = 495
- Left = 4200
- TabIndex = 6
- Top = 960
- Width = 1395
- End
- Begin Label Label1
- Caption = "Picture to combine."
- Height = 495
- Left = 4200
- TabIndex = 5
- Top = 360
- Width = 1395
- End
- Option Explicit
- ' We use these variables to keep track of whether the
- ' car is currently merged, and if so, where.
- Dim CarIsMerged%
- Dim CarMergeLocX%
- Dim CarMergeLocY%
- Sub cmdClose_Click ()
- Unload Me
- End Sub
- ' This routine combines the car into the leaf spread
- ' x and y are the start position for the merge in the leaf
- ' picture
- ' We'll use x = -1000 to indicate that the existing car
- ' location should be cleared.
- Sub CombineImage (X%, Y%)
- Dim di%
- If CarIsMerged% Then
- ' Car is already merged - we had better remove
- ' it before merging it into the new location
- ' This is accomplished by simply restoring
- ' the saved area.
- di% = BitBlt(picLeafs.hDC, CarMergeLocX%, CarMergeLocY%, 32, 32, picSaved.hDC, 0, 0, SRCCOPY)
- CarIsMerged% = False
- End If
- If X% = -1000 Then Exit Sub
- ' Lets start by bringing in a portion of the leaf
- ' spread into the work picture.
- di% = BitBlt(picWork.hDC, 0, 0, 32, 32, picLeafs.hDC, X%, Y%, SRCCOPY)
- ' We'll also hold the image in the saved area
- di% = BitBlt(picSaved.hDC, 0, 0, 32, 32, picLeafs.hDC, X%, Y%, SRCCOPY)
- ' In a real application, we would perform all of the
- ' following operations on the same work picture.
- ' For illustrative purposes, we're using multiple
- ' pictures.
- ' Now lets Force to white the car area
- ' First bring over the current work area.
- di% = BitBlt(picWork2.hDC, 0, 0, 32, 32, picWork.hDC, 0, 0, SRCCOPY)
- ' Now OR in the inverted mask
- di% = BitBlt(picWork2.hDC, 0, 0, 32, 32, picCarMaskI.hDC, 0, 0, SRCPAINT)
- ' Now lets merge in the car
- ' First, bring over the current work area.
- di% = BitBlt(picWork3.hDC, 0, 0, 32, 32, picWork2.hDC, 0, 0, SRCCOPY)
- ' Now AND in the car picture
- di% = BitBlt(picWork3.hDC, 0, 0, 32, 32, picCar.hDC, 0, 0, SRCAND)
- ' And finally, Copy the bitmap back to the original spread
- di% = BitBlt(picLeafs.hDC, X%, Y%, 32, 32, picWork3.hDC, 0, 0, SRCCOPY)
- ' Save the current status
- CarIsMerged% = True
- CarMergeLocX% = X%
- CarMergeLocY% = Y%
- End Sub
- Sub Form_Load ()
- Dim di%
- ' Note that in order for this BitBlt to work during
- ' form load, both of these picture controls must have
- ' autoredraw set to True - this assures that the
- ' device context refers to a real bitmap at all times.
- di% = BitBlt(picCarMaskI.hDC, 0, 0, 32, 32, picCarMask.hDC, 0, 0, SRCINVERT)
- End Sub
- Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
- CombineImage -1000, -1000
- End Sub
- Sub picLeafs_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
- Dim usex%, usey%
- ' It's safe to use integers here, as we've set the
- ' scalemode to pixels.
- usex% = X
- usey% = Y
- ' Rather than go through the hassle of partial bitmaps,
- ' we'll simply restrict the merge area to valid parts
- ' of the leaf picture control
- ' Important: We know that we're using a 32x32 pixel
- ' merge field. A robust version of this program would
- ' have to calculate the actual size of the merged image
- If usex% < 0 Then usex% = 0
- If usey% < 0 Then usey% = 0
- If usex% + 32 > picLeafs.ScaleWidth Then usex% = picLeafs.ScaleWidth - 32
- If usey% + 32 > picLeafs.ScaleHeight Then usey% = picLeafs.ScaleHeight - 32
- CombineImage usex%, usey%
- End Sub
-